package com.test;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


class SubTask implements Callable<Integer>
{

	private int num;
	
	SubTask(int num)
	{
		this.num = num;
	}
	
	
	@Override
	public Integer call()
	{
		int result = 0;
		
		for(int i=0;i<num;i++)
		{
			result = result+i;
		}
		
		return result;
	}
	
}




public class CallableDemo1 
{

	public static void main(String[] args) throws InterruptedException, ExecutionException
	{
		ExecutorService executor = Executors.newSingleThreadExecutor();
		SubTask sub = new SubTask(20);
		
		Future<Integer> future = executor.submit(sub);
		
		int result = future.get();
		
		System.out.println(result );
		
		
		
		
		

	}

}
